package com.javatian.dao;

import com.javatian.entity.CartInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * 购物车信息Dao
 */
@Repository
public interface CartInfoDao extends Mapper<CartInfo> {
    /*根据用户id和用户等级查询购物车列表*/
    List<CartInfo> findCartByUserId(@Param("userId")Long userId,@Param("level")Integer level);

    /*查询所有购物车信息列表*/
    List<CartInfo> findAll();

    /*清空购物车*/
    @Delete("delete from cart_info where userId=#{userId} and level=#{level}")
    int deleteByUserId(@Param("userId")Long userId,@Param("level")Integer level);

    /*删除某用户购物车里的某个商品*/
    @Delete("delete from cart_info where userId=#{userId} and level=#{level} and goodsId=#{goodsId}")
    int deleteGoods(@Param("userId")Long userId,@Param("level")Integer level,@Param("goodsId")Long goodsId);
}
